<?php
declare (strict_types = 1);

namespace app\middleware;

use think\facade\Log;
use think\facade\Request;

class Logs
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $requestInfo = [
            'timestamp' => date('Y-m-d H:i:s',Request::time()),
            'ip'        => Request::ip(),
            'method'    => Request::method(),
            'host'      => Request::host(),
            'url'       => Request::url(),
            'header'    => Request::header(),
            'param'     => Request::param(),
        ];

        $info = "{$requestInfo['ip']} {$requestInfo['method']} {$requestInfo['host']}{$requestInfo['url']}";

        Log::div(PHP_EOL . "---------------------------------------------------------------------------------------" . PHP_EOL);
        Log::host($info);
        Log::param($requestInfo['param']);
        Log::header($requestInfo['header']);

        return $next($request);
    }

}
